<template>
  


  
    <el-container>
      <!-- 树形 -->
      <el-aside width="200px">
          <!-- <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="addTree(1)"
                    :disabled="addDisabled"></el-button>
                <el-button class="filter-item" size="mini" type="success" icon="el-icon-edit" @click="addTree(2)"
                    :disabled="updateDelelteDisabled"></el-button>
                <el-button class="filter-item" type="danger" icon="el-icon-delete" size="mini" @click="deleteTree()"
                    :disabled="updateDelelteDisabled"></el-button> -->
                <el-tree :expand-on-click-node="false" style="max-width: 600px" :data="treeData" :props="defaultProps"
                    @node-click="handleNodeClick" />
      </el-aside>
      <!-- 代码主要部分 -->
      <el-main>
        <div>
      <el-form :model="form" label-width="auto" :inline="true">


            <el-form-item label="库存形态">
                <el-select v-model="form.region" placeholder="请选择" style="width: 150px;" >
                  <el-option label="Zone one" value="shanghai" />
                  <el-option label="Zone two" value="beijing" />
                </el-select>
            </el-form-item>

            <el-form-item label="库位编码">
                  <el-input v-model="form.name" style="width: 150px;"  />
            </el-form-item>

            <el-form-item label="商品">
                  <el-input v-model="form.name" style="width: 150px;"  />
            </el-form-item>

            <el-form-item label="品牌">
                <el-select v-model="form.region" placeholder="请选择" style="width: 150px;" >
                  <el-option label="Zone one" value="shanghai" />
                  <el-option label="Zone two" value="beijing" />
                </el-select>
            </el-form-item>

            <el-form-item label="规格">
                  <el-input v-model="form.name" style="width: 150px;"  />
            </el-form-item>

            <el-form-item label="规格实际库存" >
                  <el-input v-model="form.name" style="width: 120px; "  />
                  至
                  <el-input v-model="form.name" style="width: 120px;"  />
            </el-form-item>

            <el-form-item label="规格">
                  <el-input v-model="form.name" placeholder="编码或规格值"  style="width: 150px;"  />
            </el-form-item>

            <el-form-item label="条码">
                  <el-input v-model="form.name"  style="width: 150px;"  />
            </el-form-item>
            
            <el-form-item label="使用方式">
                <el-select v-model="form.region" placeholder="请选择" style="width: 150px;" >
                  <el-option label="Zone one" value="shanghai" />
                  <el-option label="Zone two" value="beijing" />
                </el-select>
            </el-form-item>


      </el-form>
    </div>
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="listQuery.Filter" clearable size="small" placeholder="搜索..." style="width: 200px;"
        class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search"
        @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus"
        @click="handleCreate">新增</el-button>
      <!-- <el-button class="filter-item" size="mini" type="success" icon="el-icon-edit"
        @click="handleUpdate()">修改</el-button>
      <el-button slot="reference" class="filter-item" type="danger" icon="el-icon-delete" size="mini"
        @click="handleDelete()">删除</el-button> -->
        <el-button class="filter-item" size="mini" type="primary" icon="el-icon-download"
        @click="handleExport()">导出</el-button>
        <span>
         <h4>当前商品汇总：共<span style="color: red;">0</span>件</h4>
      </span>
    </div>
    <el-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" @close="cancel()"
      :title="formTitle">
      <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="库存数量实际" prop="Investoryquantityactual">
          <el-input v-model="form.Investoryquantityactual" placeholder="请输入库存数量实际" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="库存数量可用" prop="Inventoryquantityavailable">
          <el-input v-model="form.Inventoryquantityavailable" placeholder="请输入库存数量可用" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="库存数量冻结" prop="Inventoryquantityfrozen">
          <el-input v-model="form.Inventoryquantityfrozen" placeholder="请输入库存数量冻结" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="库存数量锁定" prop="Inventoryquantitylocking">
          <el-input v-model="form.Inventoryquantitylocking" placeholder="请输入库存数量锁定" clearable
            :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button size="small" type="text" @click="cancel">取消</el-button>
        <el-button size="small" v-loading="formLoading" type="primary" @click="save">确认</el-button>
      </div>
    </el-dialog>
    <el-table ref="multipleTable" v-loading="listLoading" :data="list" size="small" style="width: 90%;"
      @sort-change="sortChange" @selection-change="handleSelectionChange" @row-click="handleRowClick">
      <el-table-column type="selection" width="44px"></el-table-column>
      <el-table-column label="图"  align="center" />
      <el-table-column label="库区"  align="center" />
      <el-table-column label="库位编码"  align="center" />
      <el-table-column label="使用方式"  align="center" />
      <el-table-column label="商品名称/规格"  align="center" />
      <el-table-column label="商品编码"  align="center" />
      <el-table-column label="商品条码"  align="center" />
      <el-table-column label="货号"  align="center" />
      <el-table-column label="单位"  align="center" />
      <el-table-column label="库存数量"  align="center">
          <el-table-column label="库存数量实际" prop="Investoryquantityactual" align="center" />
          <el-table-column label="库存数量可用" prop="Inventoryquantityavailable" align="center" />
          <el-table-column label="库存数量冻结" prop="Inventoryquantityfrozen" align="center" />
          <el-table-column label="库存数量锁定" prop="Inventoryquantitylocking" align="center" />
      </el-table-column>
      
      <el-table-column label="操作" align="center">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)" icon="el-icon-edit" />
          <el-button type="danger" size="mini" @click="handleDelete(row)" icon="el-icon-delete" />
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="totalCount>0" :total="totalCount" :page.sync="page"
      :limit.sync="listQuery.MaxResultCount" @pagination="getList" />
      </el-main>
    </el-container>



   
 
</template>
<script>
import Pagination from "@/components/Pagination";
import permission from "@/directive/permission/index.js";
const defaultForm = {
  id: null,
  Investoryquantityactual: null,
  Inventoryquantityavailable: null,
  Inventoryquantityfrozen: null,
  Inventoryquantitylocking: null,
}
export default {
  name: 'Inventoryquantity',
  components: {
    Pagination
  },
  directives: {
    permission
  },
  props: [],
  data() {
    return {
      treefrom: {
                id: "",
                code: "",
                pCode: "",
                name: ""
            },
      rules: {
        Investoryquantityactual: [{
          required: true,
          message: '请输入库存数量实际',
          trigger: 'blur'
        }],
        Inventoryquantityavailable: [{
          required: true,
          message: '请输入库存数量可用',
          trigger: 'blur'
        }],
        Inventoryquantityfrozen: [{
          required: true,
          message: '请输入库存数量冻结',
          trigger: 'blur'
        }],
        Inventoryquantitylocking: [{
          required: true,
          message: '请输入库存数量锁定',
          trigger: 'blur'
        }],
      },
      dialogFormVisibleAdd: false,  //打开新增弹窗或修改
            onTreeData: null, //点击树型结构 获取的 数据
            treeData: null, // 树型结构数据
            defaultProps: {         // 树型结构配置
                children: 'children',
                label: 'label',
            },
      form: Object.assign({}, defaultForm),
      list: null,
      totalCount: 0,
      listLoading: true,
      formLoading: false,
      listQuery: {
        Filter: '',
        Sorting: '',
        SkipCount: 0,
        MaxResultCount: 10
      },
      page: 1,
      dialogFormVisible: false,
      multipleSelection: [],
      formTitle: '',
      isEdit: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getList()
    this.getTreeData()  // 获取树型结构数据
  },
  mounted() {},
  methods: {
    // 树型结构数据获取
    getTreeData() {
            this.$axios.gets('/api/business/Warehouse/data').then(response => {
                this.treeData = response.items;
            });
        },
    getList() {
      this.listLoading = true;
      this.listQuery.SkipCount = (this.page - 1) * this.listQuery.MaxResultCount;
      this.$axios.gets('/api/business/Inventoryquantity', this.listQuery).then(response => {
        this.list = response.items;
        this.totalCount = response.totalCount;
        this.listLoading = false;
      });
    },
    fetchData(id) {
      this.$axios.gets('/api/business/Inventoryquantity/' + id).then(response => {
        this.form = response;
      });
    },
    handleFilter() {
      this.page = 1;
      this.getList();
    },
    handleCreate() {
      this.formTitle = '新增库存数量';
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    handleDelete(row) {
      var params = [];
      let alert = '';
      if (row) {
        params.push(row.id);
        alert = row.name;
      }
      else {
        if (this.multipleSelection.length === 0) {
          this.$message({
            message: '未选择',
            type: 'warning'
          });
          return;
        }
        this.multipleSelection.forEach(element => {
          let id = element.id;
          params.push(id);
        });
        alert = '选中项';
      }
      this.$confirm('是否删除' + alert + '?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.posts('/api/business/Inventoryquantity/delete', params).then(response => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          });
          this.getList();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleUpdate(row) {
      this.formTitle = '修改库存数量';
      this.isEdit = true;
      if (row) {
        this.fetchData(row.id);
        this.dialogFormVisible = true;
      }
      else {
        if (this.multipleSelection.length != 1) {
          this.$message({
            message: '编辑必须选择单行',
            type: 'warning'
          });
          return;
        }
        else {
          this.fetchData(this.multipleSelection[0].id);
          this.dialogFormVisible = true;
        }
      }
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.formLoading = true;
          this.form.roleNames = this.checkedRole;
          if (this.isEdit) {
            this.$axios.posts('/api/business/Inventoryquantity/data-post', this.form).then(response => {
              this.formLoading = false;
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 2000
              });
              this.dialogFormVisible = false;
              this.getList();
            }).catch(() => {
              this.formLoading = false;
            });
          }
          else {
            this.$axios.posts('/api/business/Inventoryquantity/data-post', this.form).then(response => {
              this.formLoading = false;
              this.$notify({
                title: '成功',
                message: '新增成功',
                type: 'success',
                duration: 2000
              });
              this.dialogFormVisible = false;
              this.getList();
            }).catch(() => {
              this.formLoading = false;
            });
          }
        }
      });
    },
    sortChange(data) {
      const {
        prop,
        order
      } = data;
      if (!prop || !order) {
        this.handleFilter();
        return;
      }
      this.listQuery.Sorting = prop + ' ' + order;
      this.handleFilter();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    cancel() {
      this.form = Object.assign({}, defaultForm);
      this.dialogFormVisible = false;
      this.$refs.form.clearValidate();
    },
  }
}

</script>
<style>
</style>
